package com.zpark.controller;

import com.zpark.pojo.Ranking;
import com.zpark.service.IRankingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaoyu
 * @version 1.0 2022/10/11
 */
@RestController
public class RankingController {
    @Autowired
    private IRankingService rankingService;

    @RequestMapping("/all")
    public List<Ranking> all(){
        return rankingService.findAll();
    }

    @RequestMapping("/del/{id}")
    public String remove(@PathVariable Integer id){

        Integer row = rankingService.remove(id);

        return "删除数据：" + row;
    }

    @RequestMapping("/update")
    public String cheange(@RequestBody Ranking ranking){
        System.err.println(ranking.toString());
        Integer row = rankingService.change(ranking);

        return "修改数据数据：" + row;
    }

    @RequestMapping("/add")
    public String add(Ranking ranking){
        Integer row = rankingService.add(ranking);

        return "添加数据：" + row;
    }

    @GetMapping("/find_id/{id}")
    public Ranking findById(@PathVariable Integer id){
        return rankingService.findById(id);
    }

    @PostMapping("/find_other")
    public List<Ranking> findByOther(Ranking ranking){
        return rankingService.findByOther(ranking);
    }


    @RequestMapping("/page/{startPage}/{size}")
    public List<Ranking> findPage(@PathVariable Integer startPage, @PathVariable Integer size){
        return rankingService.findPage(startPage, size);
    }
}
